#ifndef WINTUN_DRIVER_H
#define WINTUN_DRIVER_H

#include "spsc_queue.h"
#include "wintun.h"
#include "netpacket_pool.h"

using cb_outbound_data = std::function<void(std::shared_ptr<NetPacket>)>;

class WintunDriver
{
public:
    WintunDriver();
    ~WintunDriver();
    bool init(cb_outbound_data func);
    //向驱动注入入站数据包
    void doWrite(NetPacket* buffer);
private:
    void sendPackets();
    void receivePackets();
    SPSCQueue<NetPacket*> queue_inject_;
    std::atomic_flag queue_inject_nonempty_{};
    std::atomic_flag is_close_ = ATOMIC_FLAG_INIT;
    HANDLE event_close_;
    cb_outbound_data cb_out_data_;

    std::vector<std::thread> workers_;
    WINTUN_SESSION_HANDLE session_;
    WINTUN_ADAPTER_HANDLE adapter_;
};

#endif // WINTUN_DRIVER_H
